user_table = {"lzw":"123456","lzc":"6688"}
goods_name = {'001':'斯伯丁篮球','002':'安慕希酸奶','003':'德芙巧克力','004':'养乐多'}
goods_price = {'001':168,'002':68,'003':35,'004':12}
users = {}
buy = {}
budget = 0


def login_required(func):
    def inner(*args,**kwargs):
        if users:
            func(*args,**kwargs)
        else:
            print("用户未登陆，请登陆后重试")
    return inner

def market_goods():
    for i, j in goods_name.items():
        print(f"编号{i},商品是{j},价格是{goods_price[i]}")

def loggin():
    global budget
    print("退出请输入exit")
    name = input("请输入用户名：")
    passwd = input("请输入密码：")
    if passwd == user_table.get(name,-1):
        print("欢迎登入三乐购物系统")
        users[name] = passwd
        while True:
            budget = input("请输入你的预算(必须是整数):")
            if budget.isdigit():
                break
            else:
                print("输入的预算有误，请重新输入")
    else:
        print("用户名密码输入有误")
        return False

@login_required
def shopping():
    global budget
    num1 = input("请输入购买商品的编号：")
    if num1 in goods_price:
        budget = int(budget)
        if budget >= goods_price[num1]:
            budget -= goods_price[num1]
            buy[goods_name[num1]] = goods_price[num1]

            print(f"您已成功购买编号{num1}商品")
        else:
            print("余额不足，请充值")
    elif num1 == "exit":
        for i in buy:
            print(f"已购买商品{i},余额{budget}")
            break
    else:
        print("输入商品的编号有误")

@login_required
def check_budget(budget1):
    print(f"余额还有{budget1}元")

while True:
    print("欢迎进入三乐购物系统")
    num = input("查看超市商品请输入1，查看余额信息请按2，购买商品请按3，登陆用户请按4，退出输入exit:")
    if num == "1":
        market_goods()
    elif num == "2":
        check_budget(budget)
    elif num == "3":
        shopping()
    elif num == "4":
        loggin()
    elif num == "exit":
        print("已退出三乐购物系统")
        break
    else:
        print("输入有误，请重新输入")









































